<template>
  <div>
    <div class="infowin_wrapper">
      <div class="header">
        <span>{{ site.siteName }}</span>
      </div>
      <div class="banner">
        <router-link class="back" to="/login">
          <el-button
            type="primary"
            plain
            size="mini"
            icon="el-icon-s-home"
          >首页
          </el-button>
        </router-link>
        <span class="date">{{ date }}</span>
      </div>
      <div class="body">
        <!-- <div v-if="!(imageFlag || panoramaFlag)" class="tip">此基地下暂无任何数据</div> -->
        <el-card class="site_info">
          <div class="title">{{ site.siteName }}</div>
          <div class="col">
            <div>基地地址：</div>
            <div>{{ address | handleEmpty }}</div>
          </div>
          <div class="col">
            <div>详细地址：</div>
            <div>{{ site.location }}</div>
          </div>
          <div class="col">
            <div>基地简介：</div>
            <div>{{ site.remarks }}</div>
          </div>
          <div v-if="videoFlag" class="col">
            <div>在线视频：</div>
            <div class="tags">
              <el-tag
                v-for="(item, index) of siteVideos"
                :key="item.id"
                size="mini"
                style="margin-right:5px;cursor:pointer;"
                @click.native="openVideoDialog(item)"
              >
                <i class="el-icon-video-camera" />
                <span>视频{{ index + 1 }}</span>
              </el-tag>
            </div>
          </div>
        </el-card>
        <div v-if="imageFlag" class="image_wrapper">
          <div class="title">基地图片</div>
          <el-row>
            <el-col v-for="item of siteImages" :key="item.id" class="image_inner" :span="8">
              <el-image :src="item.image" class="image" :preview-src-list="previewList" />
            </el-col>
          </el-row>
        </div>
        <div v-if="panoramaFlag" class="image_wrapper">
          <div class="title">全景摄像</div>
          <el-row>
            <el-col v-for="item of panoramas" :key="item.id" class="image_inner" :span="8">
              <el-link type="primary" :href="item.overallURL" :underline="false" class="link">
                <el-image :src="item.image" class="image" />
              </el-link>
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
    <video-dialog
      title="基地视频"
      :video-dialog-visible="videoDialogVisible"
      :video-url="videoUrl"
      @close="closeVideoDialog"
    />
  </div>
</template>

<script>
import { parseTime } from '@/utils/index'
import VideoDialog from './VideoDialog'

export default {
  name: 'InfoWin',
  components: {
    VideoDialog
  },
  filters: {
    handleEmpty(value) {
      return value === '' ? '暂未录入' : value
    }
  },
  props: {
    site: {
      type: Object,
      required: true
    },
    siteImages: {
      type: Array,
      required: true
    },
    panoramas: {
      type: Array,
      required: true
    },
    siteVideos: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      keys: '',
      videoDialogVisible: false,
      videoUrl: '',
      date: parseTime(new Date(), '{y}年{m}月{d}日')
    }
  },
  computed: {
    previewList() {
      return this.siteImages.map(item => {
        return item.image
      })
    },
    imageFlag() {
      return this.siteImages.length !== 0
    },
    panoramaFlag() {
      return this.panoramas.length !== 0
    },
    videoFlag() {
      return this.siteVideos.length !== 0
    },
    address() {
      const site = this.site
      return site.province + site.city + site.county
    }
  },
  methods: {
    login() {
      this.$emit('login')
    },
    search() {
      console.log(111)
      this.$emit('search', this.keys)
    },
    openVideoDialog(item) {
      this.videoDialogVisible = true
      this.videoUrl = item.videoUrl
    },
    closeVideoDialog() {
      this.videoDialogVisible = false
    },
    routeTo(siteId) {
      this.$emit('route-to', siteId)
    }
  }
}
</script>

<style scoped lang="scss">
.infowin_wrapper {
  width:350px;
  position:absolute;
  top:10%;
  bottom:10%;
  z-index:2;
  margin-left:8%;
  background-color:#fff;
  border-radius:8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
  overflow: hidden;
  .header {
    height:48px;
    display:flex;
    justify-content: center;
    background-color:#409EFF;
    font-size:15px;
    color:#fff;
    padding:10px;
    line-height:28px;
    .back {
      position:absolute;
      left:10px;
    }
  }
  .banner {
    padding:8px 10px;
    display:flex;
    justify-content: space-between;
    align-items: center;
    border-bottom:1px solid rgb(235,235,235);
    .date {
      color:#409EFF
    }
  }
  .body {
    width:100%;
    position:absolute;
    top:94px;
    bottom:0;
    overflow-y: scroll;
    .tip {
      padding:10px;
      text-align: center;
      color:#999;
      font-size:13px;
    }
    .site_info {
      margin:10px;
      color:#409EFF;
      .title {
        margin-bottom:20px;
        font-weight:bolder;
      }
      .col {
        display:flex;
        font-size:15px;
      }
      .col:not(:last-child) {
        padding-bottom: 8px;
      }
    }
    .image_wrapper {
      .title {
        color:#409EFF;
        font-size:13px;
        padding:10px 10px 0 10px;
        font-weight:bolder;
      }
      .image_inner {
        display:flex;
        justify-content: center;
        align-items: center;
        padding:10px 0;
        .link {
          display:flex;
          justify-content: center;
          align-items: center;
          .image {
            display:block;
            margin:0 auto;
          }
        }
        .image {
          width:80%;
          height:70px;
          border-radius: 5px;
          box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
        }
      }

    }
  }
}

</style>
